package com.syyo.admin.interceptor;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Auther: wangzhong
 * @Date: 2019/7/29 16:29
 * @Description:
 *
 */
@Configuration
@ComponentScan(value="com.syyo.admin.interceptor")    //扫描拦截器所在的包
public class WebAppConfig implements WebMvcConfigurer {

    private AuthorityInterceptor authorityInterceptor;

    @Autowired
    public WebAppConfig(AuthorityInterceptor authorityInterceptor) {
        this.authorityInterceptor = authorityInterceptor;

    }

    /**
     * /swagger-resources/**
     * /swagger-ui.html
     * /v2/api-docs
     * /webjars/**
     * /webSocket/**
     *
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorityInterceptor).addPathPatterns("/**")   //拦截所有
                .excludePathPatterns("/auth/logout","/auth/code","/auth/db")
                .excludePathPatterns("/swagger-resources/**","/swagger-ui.html","/v2/api-docs","/webjars/**");
    }
}
